<template>
<div>
  <Meta v-if="schoolDataset.name!==undefined" pagealias="schoolshow" :custom_data="{name:schoolDataset.name}" />
  <Head>院校详情</Head>
  <div class="bg" v-cloak>
    <div class="banner"></div>
    <div class="info_bg">
      <div class="sd_info_con">

          <div class="sd_info_pos">
            <van-skeleton title avatar :row="3" avatar-size="50" :row-width="[210,220,230,240]" :loading="loading" :animate="false">
              <div class="sd_info">
                <div class="school_img">
                  <img :src="schoolDataset.logo_url" alt="">
                </div>
                <div class="sd_share" @click="isShow=true">
                  <a href="javascript:;" class="link"></a>
                </div>
                <div class="school_title substring">{{schoolDataset.name}}</div>
                <div class="oth_list">
                  <a class="oth_btn">{{schoolDataset.type_cn}}</a>
                  <a class="oth_btn">{{schoolDataset.level_cn}}</a>
                </div>
                <p class="info_text_1 substring">{{schoolDataset.district_cn}}</p>
                <p class="info_text_2 substring">{{schoolDataset.tel ? schoolDataset.tel : '暂无电话' }}</p>
              </div>
            </van-skeleton>
          </div>

          <div class="info_box">
            <div class="sd_toggles j_sd_btn">
              <div :class="index==0 ? 'toggles_btn toggles_btn_active' : 'toggles_btn'" @click="tab(0)">院校描述</div>
              <div :class="index==1 ? 'toggles_btn toggles_btn_active' : 'toggles_btn'"  @click="tab(1)">宣讲会</div>
              <div :class="index==2 ? 'toggles_btn toggles_btn_active' : 'toggles_btn'" @click="tab(2)">双选会</div>
            </div>
            <div class="info_list j_info_list">
              <!-- 院校描述 -->
              <div class="editor-content-view" :class=" index== 0 ?'info_item schoool_introduce info_item_active':'info_item schoool_introduce'"  v-show="index==0">
                <div v-html="schoolDataset.introduction"></div>
              </div>
              <!-- 宣讲会 -->
              <div :class=" index== 1 ?'info_item schoool_declare info_item_active':'info_item schoool_introduce'" v-show="index==1">
                <van-empty image="search" description="没有找到对应的数据" style="background-color:#fff" v-if="preach_show_empty === true"/>
                <van-list v-if="preachDataset.length > 0" :finished="preachFinished" @load="preachLoading()" v-model="preachLoadingShow" :finished-text="preachFinishedText">
                  <div class="s_declare_item" v-for="(item, index) in preachDataset" :key="index">
                    <a class="preach_more" @click="$router.push('/campus/preach/' +  item.id)">查看详情</a>
                    <a class="substring declare_name">{{item.subject}}</a>
                    <p class="substring declare_date">时间：{{item.starttime}}</p>
                    <p class="substring declare_address">地点：{{item.address}}</p>
                  </div>
                </van-list>
              </div>
              <!-- 双选会 -->
              <div :class=" index== 2 ?'info_item schoool_declare info_item_active':'info_item schoool_introduce'" v-show="index==2">
                <van-empty image="search" description="没有找到对应的数据" style="background-color:#fff" v-if="electio_show_empty === true"/>
                <van-list v-if="electionDataset.length > 0" :finished="electionFinished" @load="electionLoading()" v-model="electionLoadingShow" :finished-text="electionFinishedText">
                  <div class="s_declare_item" v-for="(item, index) in electionDataset" :key="index" @click="$router.push('/campus/election/' + item.id)">
                    <span :class="item.score == 0 ? 'item_icon item_icon_end' : item.score == 1 ? 'item_icon item_icon_start' : 'item_icon item_icon_progress'" >{{item.score == 0 ? '已结束' : item.score == 1 ? '即将开始' : '进行中'}}</span>
                    <a class="substring declare_name">{{item.subject}}</a>
                    <p class="substring declare_date">时间：{{item.starttime}} 至 {{item.endtime}}</p>
                    <p class="substring declare_address">地点：{{item.address}}</p>
                  </div>
                </van-list>
              </div>
            </div>
          </div>
      </div>
    </div>
    <div class="alw_layer" v-show="isShow" @click="isShow=false"></div>
  </div>
</div>
</template>

<script>
import {parseTime} from '@/utils/index'
import http from '@/utils/http.js'
import api from '@/api.js'
export default{
  beforeMount () {
    // 自定义body背景色
    document
      .querySelector('body')
      .setAttribute('style', 'background-color:#fff')
  },
  beforeDestroy () {
    // 去掉自定义body背景色
    document.querySelector('body').removeAttribute('style')
  },
  data () {
    return {
      preach_show_empty: false,
      electio_show_empty: false,
      isShow: false,
      index: 0,
      loading: true,
      school_show_id: null,
      preachParams: {
        school_id: null
      },
      preachPage: 1,
      preachPagesize: 10,
      preachFinishedText: '',
      preachFinished: false,
      preachLoadingShow: false,
      electionParams: {
        school_id: null
      },
      electionPage: 1,
      electionPagesize: 10,
      electionFinishedText: '',
      electionFinished: false,
      electionLoadingShow: false,
      schoolDataset: {},
      electionDataset: [],
      preachDataset: []
    }
  },
  filters: {
    timeFilter (timestamp) {
      return parseTime(timestamp, '{y}-{m}-{d}')
    }
  },
  created () {
    this.school_show_id = this.$route.params.id
  },
  mounted () {
    this.getSchoolShow()
    // 获取院校详情宣讲会列表
    this.getSchoolPreach(true)
    // 获取院校详情宣讲会列表
    this.getSchoolElection(true)
  },
  methods: {
    tab (index) {
      this.index = index
      this.preachFinished = false
      this.preachLoadingShow = false
      this.electionFinished = false
      this.electionLoadingShow = false
    },
    preachLoading () {
      this.preachPage++
      this.getSchoolPreach(false)
    },
    electionLoading () {
      this.electionPage++
      this.getSchoolElection(false)
    },
    // 获取院校详情
    getSchoolShow () {
      http.get(api.school_show, {id: this.school_show_id}).then((res) => {
        this.schoolDataset = res.data.info
        if (this.schoolDataset) {
          this.loading = false
        }
      })
    },
    // 获取院校详情宣讲会列表
    getSchoolPreach (init) {
      this.preach_show_empty = false
      let conditions = {...this.preachParams}
      if (init === true) {
        this.preachPage = 1
        this.preachFinishedText = ''
      }
      conditions.page = this.preachPage
      conditions.pagesize = this.preachPagesize
      conditions.school_id = this.school_show_id
      http.get(api.school_preach, conditions).then((res) => {
        if (init === true) {
          this.preachDataset = [...res.data.item]
        } else {
          this.preachDataset = this.preachDataset.concat(res.data.item)
        }
        // 加载状态结束
        this.preachLoadingShow = false
        if (res.data.item.length < this.preachPagesize) {
          this.preachFinished = true
          if (init === false) {
            this.preachFinishedText = '没有更多了'
          } else if (res.data.item.length === 0) {
            this.preach_show_empty = true
          }
        }
      })
    },
    // 获取院校详情双选会列表
    getSchoolElection (init) {
      this.electio_show_empty = false
      let conditions = {...this.electionParams}
      if (init === true) {
        this.electionPage = 1
        this.electionFinishedText = ''
      }
      conditions.page = this.electionPage
      conditions.pagesize = this.electionPagesize
      conditions.school_id = this.school_show_id
      http.get(api.school_election, conditions).then((res) => {
        if (init === true) {
          this.electionDataset = res.data.item
        } else {
          this.electionDataset = this.electionDataset.concat(res.data.item)
        }
        // 加载状态结束
        this.electionLoadingShow = false
        if (res.data.item.length < this.preachPagesize) {
          this.electionFinished = true
          if (init === false) {
            this.electionFinishedText = '没有更多了'
          } else if (res.data.item.length === 0) {
            this.electio_show_empty = true
          }
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.van-skeleton {
  width: 100%;
  height: 150px;
  padding: 20px ;
  position: absolute;
  top: -75px;
  background: #fff;
  border-radius: 5px;
  box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.05);
}
html {
  height: 100%;
}
.bg {
  background: url(../../../assets/images/campus/school_details.png) no-repeat top center/100%;
}

.banner {
  height:163.5px;
}
.info_bg {
  // background-color: #f4f7fc;
}
.sd_info_con {
  margin: 0 9px 0 10.5px;
}

.sd_info_con .sd_info_pos {
  position: relative;
  height: 80px;
}

.sd_info_con .sd_info {
  width: 100%;
  height: 150px;
  background-color: #fff;
  border-radius: 5px;
  box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.05);
  margin-bottom: 15px;
  position: absolute;
  top: -75px;
}
.sd_info_con .sd_info .school_img {
  width: 65px;
  height:65px;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 1px 1px 2px 2px rgba(0, 0, 0, 0.05);
  position: absolute;
  top: -25px;
  left: 15px;
}

.sd_info_con .sd_info .school_img img {
  width:45px;
  height:45px;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  margin: auto;
}

.sd_info_con .sd_info .sd_share {
  width: 20px;
  height: 20px;
  position: absolute;
  right: 14.5px;
  top: 10px;
  background: url(../../../assets/images/campus/detail_share.png) no-repeat center center/16px 14.5px;
}

.sd_info_con .sd_info .sd_share .link{
  width: 100%;
  height: 100%;
  display: block;
}

.sd_info_con .sd_info .school_title {
  color: #333333;
  font-size: 19px;
  margin-bottom: 10px;
  max-width: 190px;
  margin-left: 100px;
  padding-top: 5px;
}
.sd_info_con .sd_info .oth_list {
  display: flex;
  justify-content: center;
  margin-bottom: 15px;
}
.sd_info_con .sd_info .oth_list .oth_btn {
  color: #fcfdfe;
  font-size:12px;
  background-color: #07cc89;
  padding: 4px 16px 4px 16px;
  border-radius: 15px;
  margin-right: 7.5px;
}
.sd_info_con .sd_info .info_text_1,
.sd_info_con .sd_info .info_text_2 {
  color: #444444;
  font-size: 13px;
  margin-left: 21px;
  padding-left: 26.5px;
}
.sd_info_con .sd_info .info_text_1 {
  background: url(../../../assets/images/campus/detail_3.png) no-repeat left center/13.5px 13.5px;
  margin-bottom: 10px;
}

.sd_info_con .sd_info .info_text_2 {
  background: url(../../../assets/images/campus/detail_4.png) no-repeat left center/13.5px 13.5px;
}
.info_box {
  min-height: 325px;
  padding-bottom: 1px;
}
.sd_toggles {
  display: flex;
  justify-content: center;
}

.sd_toggles .toggles_btn {
  padding: 16px 17.5px;
  position: relative;
  font-size: 15px;
}
.sd_toggles .toggles_btn::before {
  content: "";
  width: 20.5px;
  height: 5px;
  background: linear-gradient(to right, #01d086, #07deba);
  border-radius: 5px;
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  display: none;
}
.sd_toggles .toggles_btn_active {
  font-weight: bold;
  font-size:18px;
}
.sd_toggles .toggles_btn_active::before {
  display: block;
}

.info_list {
  margin: 0 10px;
}

.info_list .info_item_active {
  display: block;
}
/* 院校描述 */
.info_list .schoool_introduce {
  background-color: #fff;
  padding: 20px 18px 35px;
  color: #444444;
  font-size: 14px;
  word-break: break-word;
}
/* 宣讲会 双选会*/
.info_list .schoool_declare .s_declare_item {
  height: 112.5px;
  background-color: #fff;
  margin-bottom: 8.5px;
  position: relative;
  padding: 17.5px 18.5px;
}
.schoool_declare .s_declare_item .item_icon {
  display: block;
  position: absolute;
  right: 0;
  top: 16.5px;
  width: 54px;
  height: 23px;
  color: #ffffff;
  font-size: 12px;
  text-align: center;
  line-height: 23px;
  border-radius: 4px 0 0 4px;
}
.schoool_declare .s_declare_item  .preach_more{
  font-size: 14px;
  color: #ffffff;
  display: block;
  width:80px ;
  height: 30px;
  text-align: center;
  line-height: 30px;
  background-color: #20c588;
  border-radius: 3px;
  box-shadow: 2px 2px 3px 1px #c1f3e0;
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
}

.schoool_declare .s_declare_item .item_icon_start {
  background-color: #ff976a;
}
.schoool_declare .s_declare_item .item_icon_progress {
  background-color: #01cf85;
}
.schoool_declare .s_declare_item .item_icon_end {
  background-color: #bebebe;
}

.schoool_declare .s_declare_item .declare_name {
  display: block;
  color: #333333;
  font-size: 15px;
  font-weight: bold;
  max-width:220px;
  margin-bottom: 12px;
}

.schoool_declare .s_declare_item .declare_date,
.schoool_declare .s_declare_item .declare_address {
  color: #555555;
  font-size: 14px;
  max-width: 280px;
}
.schoool_declare .s_declare_item .declare_date{
  margin-bottom: 9px;
}
.alw_layer{
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  z-index: 9999;
  background: url(../../../assets/images/campus/wzp_layer.png) no-repeat center center /320px 122px rgba(0,0,0,.8);
}
</style>
